In [1]:
import os, sys
sys.path.insert(0, '/home/trax/trax/website')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "trax.settings")
import django
django.setup()
from vehicles.models import *
from players.models import *
from tracks.models import *
names = [x.strip() for x in open("randomnames.txt", "r").read().splitlines()]
vehicles = {}
for x in Vehicle.objects.all():
    vname = x.name
    for char in "[]()-'/":
        vname = vname.replace(char, "")
    vehicles[x.pk] = vname
    
def sluggy(self):
    return ''.join( [x for x in self.title if x.isalnum()])

Track.sluggy = sluggy

def strsluggy(s):
    return ''.join( [x for x in s if x.isalnum()])

Create the CSV file


In [3]:
with open("/home/trax/trax/website/trax/static/track_driver_vehicle_kmh_dataset.csv", "w") as f:
    f.write('track,driver,vehicle,km_h,created_date\n')
    for l in Laptime.objects.all().order_by('id', 'track__title', 'player__id'):
        f.write( ','.join([
            str(x) for x in [l.track.sluggy(),
                             strsluggy(l.player.username),
                             vehicles[l.vehicle_id],
                             3600000/l.millis_per_km,
                             l.created.isoformat()
                            ]]) + '\n')

Use the CSV file


In [8]:
import numpy as np
import sklearn
from sklearn import datasets
iris = datasets.load_iris()
iris_X = iris.data
iris_y = iris.target
np.unique(iris_y)


Out[8]:
array([0, 1, 2])

In [6]:
n = 0
for t in Track.objects.all():
    if t.laptime_set.all().count() > 20:
        n += 1
n


Out[6]:
56

In [ ]:


In [ ]:


In [3]:
Laptime.objects.all().count()


Out[3]:
3006

In [23]:
names[100]


Out[23]:
'LaurindaSmolka'

In [ ]:


In [ ]:


In [3]:
import sklearn
import numpy as np
from sklearn import datasets

In [4]:
iris = datasets.load_iris()
iris_X = iris.data
iris_y = iris.target
np.unique(iris_y)


Out[4]:
array([0, 1, 2])

In [ ]: